package linuxbox.filelib.logic;

import org.apache.log4j.*;

public class PermissionEntry
{
  protected static Logger logger = Logger.getLogger(PermissionEntry.class.getName());

  //Make sure the data member name are the same as it is defined in its Bean object's SetupFields()
  public int id;
  public int objectid;
  public int userid;
  public boolean isgroup;
  public long permission;

  /*
       id  int4 not null,
       objectid int4 not null,
       userid int4 not null,
       isgroup int2 not null,
       permission int8 not null,
   */

   public PermissionEntry()
   {
   }

  public void setId(int id) {
    this.id = id;
  }

  public void setObjectid(int objectid) {
    this.objectid = objectid;
  }

  public void setUserid(int userid) {
    this.userid = userid;
  }

  public void setIsgroup(boolean isgroup) {
    this.isgroup = isgroup;
  }

  public void setPermission(long permission) {
    this.permission = permission;
  }

  public int getId() {
    return id;
  }

  public int getObjectid() {
    return objectid;
  }

  public int getUserid() {
    return userid;
  }

  public boolean getIsgroup() {
    return isgroup;
  }

  public long getPermission() {
    return permission;
  }

  public String toString()
  {
    StringBuffer str = new StringBuffer();
    if (isgroup)
      str.append("Group:");
    else
      str.append("User:");
    str.append(userid);
    str.append(" ");
    if (permission == 0)
      return str.toString();
    boolean first = true;
    if ((permission & FileLibHome.BROWSE_ALLOW) != 0)
    {
      str.append("Browse");
      first = false;
    }
    if ((permission & FileLibHome.BROWSE_DENY) != 0)
    {
      str.append("Deny Browse");
      first = false;
    }
    if ((permission & FileLibHome.READ_ALLOW) != 0)
    {
      if (!first)
        str.append("/");
      str.append("Read");
      first = false;
    }
    if ((permission & FileLibHome.READ_DENY) != 0)
    {
      if (!first)
        str.append("/");
      str.append("Deny Read");
      first = false;
    }
    if ((permission & FileLibHome.WRITE_ALLOW) != 0)
    {
      if (!first)
        str.append("/");
      str.append("Write");
      first = false;
    }
    if ((permission & FileLibHome.WRITE_DENY) != 0)
    {
      if (!first)
        str.append("/");
      str.append("Deny Write");
      first = false;
    }
    if ((permission & FileLibHome.TAKEOWNERSHIP_ALLOW) != 0)
    {
      if (!first)
        str.append("/");
      str.append("Take Ownership");
      first = false;
    }
    if ((permission & FileLibHome.TAKEOWNERSHIP_DENY) != 0)
    {
      if (!first)
        str.append("/");
      str.append("Deny Take Ownership");
      first = false;
    }
    return str.toString();
  }
 }
